<template>
  <el-form ref="formRef" :rules="rules" :model="form" label-width="120px" status-icon>
    <el-form-item label="LOGO" prop="logo">
      <KoiUploadImage v-model:imageUrl="form.logo"></KoiUploadImage>
    </el-form-item>
    <el-form-item label="用户默认头像" prop="default_avatar">
      <KoiUploadImage v-model:imageUrl="form.default_avatar"></KoiUploadImage>
    </el-form-item>
    <el-form-item label="用户协议" prop="user_agreement">
      <el-input v-model="form.user_agreement" :rows="3" type="textarea" placeholder="请输入用户协议" />
    </el-form-item>
    <el-form-item label="隐私政策" prop="privacy_policy">
      <el-input v-model="form.privacy_policy" :rows="3" type="textarea" placeholder="请输入隐私政策" />
    </el-form-item>
    <el-form-item label="购买协议" prop="purchase_agreement">
      <el-input v-model="form.purchase_agreement" :rows="3" type="textarea" placeholder="请输入购买协议" />
    </el-form-item>
    <el-form-item label="注册协议" prop="register_agreement">
      <el-input v-model="form.register_agreement" :rows="3" type="textarea" placeholder="请输入注册协议" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" plain v-debounce="handleSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { getConfig } from "@/api/system/config";

// 定义参数的类型
interface IConfigProps {
  configKey?: string;
  name?: string;
}

// 子组件接收父组件的值
// withDefaults：设置默认值  defineProps：接收父组件的参数
const props = withDefaults(defineProps<IConfigProps>(), {
  name: "",
  configKey: ""
});

onMounted(() => {
  getConfig({ key: props.configKey }).then(res => {
    if (Object.keys(res.data).length>0){
      form.value = res.data;
    }
  });
});

// 当前组件获取父组件传递的事件方法
const emits = defineEmits(["handleSubmit"]);
// 弹框的确定事件
const handleSubmit = () => {
  emits("handleSubmit", form.value);
};

let form = ref<any>({
  logo: "",
  default_avatar: "",
  user_agreement: "",
  privacy_policy: "",
  purchase_agreement: "",
  register_agreement: ""
});
</script>

<style lang="scss" scoped></style>
